package com.mhy.ssm.mapper;

import com.mhy.ssm.pojo.NewUser;
import com.mhy.ssm.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

public interface UserMapper {

    @Select("select * from user where username = #{username} and sex = #{sex}")
    List<User> selectByCond(User user);

    @Select("select * from user where username = #{username} and sex = #{sex}")
    List<Map<String, Object>> selectByCond2(Map<String, Object> map);

    @Select("select * from user where id = #{id}")
    @Results({
            @Result(id = true, column = "id", property = "userId"),
            @Result(column = "username", property = "userName"),
            @Result(column = "sex", property = "userSex"),
            @Result(column = "address", property = "userAddress")
    })
    NewUser selectById(Integer id);

    @Select("select * from user where id = #{id}")
    User selectById2(Integer id);

    @Insert("insert into user values (null, #{username}, #{birthday}, #{sex}, #{address})")
    @SelectKey(statement = "select last_insert_id()",before = false, keyProperty = "id", resultType = Integer.class)
    Integer insert(User user);

    @Select("select * from user")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "id", property = "orderList", many = @Many(select = "com.mhy.ssm.mapper.OrderMapper.getOrderByUserId"))
    })
    List<User> selectAll();
}
